<template>
	<view class="body-view">
		<button type="primary" @click="login()"> 授权登陆</button>

		<button type="primary" @click="scan()"> 扫码</button>
		<button type="primary" @click="showAction()"> 弹出框</button>

		<button type="primary" @click="getShareInfo()">获得分享信息</button>

		<button type="primary" @click="addShareInfo()">新增分享信息</button>
		<button type="primary" @click="updateShareInfo()">更新分享信息</button>
		<button type="primary" @click="getMemberInfo()">获得会员信息</button>
		<button type="primary" @click="upgradeLevel()">升级会员信息</button>
	</view>
</template>
<script>
	import mediaList from '@/components/tab-nvue/mediaList.vue';
	// import uniFab from '@/components/uni-fab/uni-fab.vue';
	import {
		request
	} from '../../api/api.js'
	export default {
		components: {
			mediaList,

		},
		data() {
			return {
				memberInfo: {},
				systemInfo: {},
				type: null,
				memberShareInfo: {}
			}
		},
		onLoad() {
			var type = null;
			// #ifdef MP-ALIPAY
			type = "zhifubao";
			// #endif
			// #ifdef MP-WEIXIN
			type = "weixin";
			// #endif
			// #ifdef MP-BAIDU
			type = "baidu";
			// #endif
			// #ifdef MP-TOUTIAO
			type = "toutiao";
			// #endif
			this.type = type;

		},
		methods: {
			login() {

				let that = this;
				console.log('来自于非支付宝平台')
				// #ifndef MP-ALIPAY
				uni.authorize({
					scope: 'scope.userInfo',
					success(userInfo) {

						uni.getUserInfo({
							success: function(infoRes) {


								that.memberInfo = infoRes.userInfo;


								//开始获得手机系统信息
								uni.getSystemInfo({
									success: function(res) {

										that.systemInfo = res;



										that.updateInfo(that.memberInfo, that.systemInfo)
									}
								});


							},
							fail(e) {
								console.log('e: ' + JSON.stringify(e));
							}
						});

					},
					fail(e) {
						console.log("e: " + JSON.stringify(e));
					}
				})
				// #endif

				// #ifdef MP-ALIPAY

				my.getAuthCode({
					scopes: 'auth_user',
					success: (res) => {
						my.getAuthUserInfo({
							success: (userInfo) => {

								that.memberInfo = userInfo

								uni.getSystemInfo({
									success: function(res) {

										that.systemInfo = res;


										that.updateInfo(that.memberInfo, that.systemInfo)
									}
								});
							}
						});
					},
				});

				// #endif


			},

			getShareInfo() {
				uni.showLoading({
					title: "加载中...."
				})
				request('memberShare/getShareInfo', null, {
					method: 'get'
				}).then((res) => {
					

					this.memberShareInfo = res.data.data[0]
					uni.hideLoading();


				})
			},
 
            upgradeLevel(){
					uni.showLoading({
					title: "加载中...."
				})
					request('member/upgradeLevel', null, {
					method: 'post'
				}).then((res) => {
				
				     console.log(res.data.data);
					 uni.setClipboardData({
					 	data:res.data.data.upgradeKey,
						success() {
							uni.getClipboardData({
								success(res) {
									console.log('成功：'+JSON.stringify(res));
								}
							})
							uni.showModal({
								title:"复制成功，赞赏时要把连接复制哦"
							})
						},
						fail(e) {
							console.log("e:"+JSON.stringify(e))
						}
					 })
					uni.hideLoading();
				
				
				})
				
			},
			addShareInfo() {
				uni.showLoading({
					title: "加载中...."
				})
				var info = {
					'title': "蛋解创业"
				}
				request('memberShare/addShareInfo', info, {
					method: 'post'
				}).then((res) => {
				

					uni.hideLoading();


				})
			},
			getMemberInfo(){
					uni.showLoading({
					title: "加载中...."
				})
				request('member/getMemberInfo', null, {
					method: 'get'
				}).then((res) => {
				
				
					uni.hideLoading();
				
				
				})
			},

			updateShareInfo() {
				uni.showLoading({
					title: "加载中...."
				})
				this.memberShareInfo.title = '洋葱科技'
				var info = {
					'title': "蛋解创业"
				}
				request('memberShare/updateShareInfo', this.memberShareInfo, {
					method: 'post'
				}).then((res) => {
					
					uni.hideLoading();


				})
			},

			updateInfo(userJSON, sysJSON) {


				console.log('userJSON: ' + JSON.stringify(userJSON))
				let userInfo = {
					userInfo: userJSON,
					systemInfo: sysJSON
				}
				//开始更新会员基本信息
				uni.showLoading({
					title: "加载中...."
				})
				request('member/updateMemberInfo', {
					userInfo: userInfo,
					type: this.type
				}, {
					method: 'post'
				}).then((res) => {
					console.log("aaa:  " + JSON.stringify(res.data.data))

					uni.hideLoading();
					uni.showToast({
						title: "更新成功"
					})

				})
			},
			scan() {
				console.log('开始扫描');
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						uni.vibrateShort({
							success: function() {
								console.log('success');
							}
						});
					},
					fail(e) {
						console.log('触发失败', JSON.stringify(e));
						uni.showToast({
							title: '失败'
						})
					},


				});

			},
			showAction() {
				uni.showActionSheet({
					itemList: ['A', 'B', 'C'],
					success: function(res) {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			}

		}
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		display: flex;
		flex-wrap: wrap;
		align-items: flex-start;
		justify-content: center;
		background: rgba(249, 249, 249, 1);
	}

	.uni-tab-bar-loading {
		text-align: center;
		font-size: 28upx;
		color: #999;
	}

	.body-view {
		display: flex;
		flex: 1;
		flex-direction: column;
		overflow: hidden;
		height: 100%;
		width: 100%;
		align-items: flex-start;
		justify-content: center;
	}

	.top-menu-view {
		display: flex;
		white-space: nowrap;
		width: 100%;
		background-color: #FFFFFF;
		height: 112upx;
		/* 在这里设置导航条高度 */
	}

	.top-menu-view .menu-one-view {
		display: inline-block;
		white-space: nowrap;
		height: 100%;
	}

	.top-menu-view .menu-one-view .menu-one {
		/* 在这里写 单个按钮样式 */
		margin-left: 25upx;
		margin-right: 25upx;
		position: relative;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.top-menu-view .menu-one-view .menu-one .menu-one-txt {
		height: 40upx;
		font-size: 28upx;
		font-weight: 400;
		color: rgba(154, 154, 154, 1);
		line-height: 40upx;
	}

	.top-menu-view .menu-one-view .menu-one .menu-one-bottom {
		position: absolute;
		bottom: 0;
		width: 100%;
	}

	.top-menu-view .menu-one-view .menu-one .menu-one-bottom .menu-one-bottom-color {
		width: 60%;
		height: 4upx;
	}

	.top-menu-view .menu-one-view .menu-one-act {
		/* 在这里写 单个按钮样式 */
		margin-left: 25upx;
		margin-right: 25upx;
		position: relative;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.top-menu-view .menu-one-view .menu-one-act .menu-one-txt {
		height: 40upx;
		font-size: 28upx;
		font-weight: 400;
		color: rgba(0, 170, 255, 1);
		line-height: 40upx;
	}

	.top-menu-view .menu-one-view .menu-one-act .menu-one-bottom {
		position: absolute;
		bottom: 0;
		width: 100%;
		display: flex;
		justify-content: center;
	}

	.top-menu-view .menu-one-view .menu-one-act .menu-one-bottom .menu-one-bottom-color {
		width: 60%;
		height: 4upx;
		background: rgba(0, 170, 255, 1);
	}

	.swiper-box-list {
		flex: 1;
		width: 100%;
		height: auto;
		background-color: #FFFFFF;
	}

	.swiper-one-list {
		height: 100%;
		width: 100%;
	}

	.swiper-one-list .swiper-list-entity {
		width: 100%;
		height: 112upx;
		text-align: center;
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: center;
	}
</style>
